package com.tianyu.inspection.common.component;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tianyu.inspection.entity.*;
import com.tianyu.inspection.entity.model.QueryMo;
import com.tianyu.inspection.mapper.*;
import com.tianyu.inspection.entity.*;
import com.tianyu.inspection.mapper.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**********************************
 * @Author YSW
 * @Description 数据层通用方法工具类
 * @Date 2021/3/2 - 14:51
 **********************************/

@Component
public class MapperModel {

    @Resource
    private CameraTypeMapper cameraTypeMapper;

    @Resource
    private ConstructionTypeMapper constructionTypeMapper;

    @Resource
    private HighConsequenceAreasTypeMapper highConsequenceAreasTypeMapper;

    @Resource
    private PileCardTypeMapper pileCardTypeMapper;

    @Resource
    private GeneralFacilitiesTypeMapper generalFacilitiesTypeMapper;

    @Resource
    private GeneralFacilitiesMapper generalFacilitiesMapper;

    @Resource
    private PipelineMapper pipelineMapper;

    @Resource
    private UserMapper userMapper;

    @Resource
    private DangerTypeMapper dangerTypeMapper;

    @Resource
    private DangerLevelMapper dangerLevelMapper;

    public Map<Integer,String> getPipelineMap(QueryMo queryMo) {
        Map<Integer,String> pipelineMap = new HashMap<>(10);
        QueryWrapper<Pipeline> wrapper = new QueryWrapper<>();
        if (Objects.nonNull(queryMo.get("projectId"))){
            wrapper.eq("project_id", queryMo.get("projectId"));
        }
        List<Pipeline> pipelineList = pipelineMapper.selectList(wrapper);
        for (Pipeline pipeline : pipelineList){
            pipelineMap.put(pipeline.getId(),pipeline.getName());
        }
        return pipelineMap;
    }

    public Map<Integer, User> getUserMap(Object projectId, Integer roleId) {
        Map<Integer,User> pipelineMap = new HashMap<>(2);
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        if (Objects.nonNull(projectId)){
            wrapper.eq("project_id", projectId);
        }
        wrapper.eq("role_id", roleId);
        List<User> pipelineList = userMapper.selectList(wrapper);
        for (User user : pipelineList){
            pipelineMap.put(user.getId(),user);
        }
        return pipelineMap;
    }


    public Map<Integer, String> getPipelineStationMap(QueryMo queryMo) {
        Map<Integer,String> pipelineStationMap = new HashMap<>(10);
        QueryWrapper<GeneralFacilities> wrapper = new QueryWrapper<>();
        if (Objects.nonNull(queryMo.get("projectId"))){
            wrapper.eq("project_id", queryMo.get("projectId"));
            wrapper.eq("general_facilities_type_id", 2);
        }
        List<GeneralFacilities> generalFacilitiesList = generalFacilitiesMapper.selectList(wrapper);
        for (GeneralFacilities generalFacilities : generalFacilitiesList){
            pipelineStationMap.put(generalFacilities.getId(),generalFacilities.getName());
        }
        return pipelineStationMap;
    }

    public Map<Integer, ConstructionType> getConstructionTypeMap() {
        Map<Integer,ConstructionType> constructionTypeMap = new HashMap<>(10);
        List<ConstructionType> constructionTypeList = constructionTypeMapper.selectList(new QueryWrapper<>());
        for (ConstructionType constructionType : constructionTypeList){
            constructionTypeMap.put(constructionType.getId(),constructionType);
        }
        return constructionTypeMap;
    }

    public Map<Integer, CameraType> getCameraTypeMap() {
        Map<Integer,CameraType> cameraTypeMap = new HashMap<>(10);
        List<CameraType> cameraTypeList = cameraTypeMapper.selectList(new QueryWrapper<>());
        for (CameraType cameraType : cameraTypeList){
            cameraTypeMap.put(cameraType.getId(),cameraType);
        }
        return cameraTypeMap;
    }

    public Map<Integer, HighConsequenceAreasType> getHighConsequenceAreasTypeMap() {
        Map<Integer,HighConsequenceAreasType> highConsequenceAreasTypeMap = new HashMap<>(10);
        List<HighConsequenceAreasType> highConsequenceAreasTypeList = highConsequenceAreasTypeMapper.selectList(new QueryWrapper<>());
        for (HighConsequenceAreasType  highConsequenceAreasType: highConsequenceAreasTypeList){
            highConsequenceAreasTypeMap.put(highConsequenceAreasType.getId(),highConsequenceAreasType);
        }
        return highConsequenceAreasTypeMap;
    }

    public Map<Integer, PileCardType> getPileCardTypeMap() {
        Map<Integer,PileCardType> pileCardTypeMap = new HashMap<>(10);
        List<PileCardType> pileCardTypeList = pileCardTypeMapper.selectList(new QueryWrapper<>());
        for (PileCardType constructionType : pileCardTypeList){
            pileCardTypeMap.put(constructionType.getId(),constructionType);
        }
        return pileCardTypeMap;
    }

    public Map<Integer, GeneralFacilitiesType> getGeneralFacilitiesTypeMap() {
        Map<Integer,GeneralFacilitiesType> valueChestTypeMap = new HashMap<>(50);
        List<GeneralFacilitiesType> generalFacilitiesTypeList = generalFacilitiesTypeMapper.selectList(new QueryWrapper<>());
        for (GeneralFacilitiesType generalFacilitiesType : generalFacilitiesTypeList){
            valueChestTypeMap.put(generalFacilitiesType.getId(), generalFacilitiesType);
        }
        return valueChestTypeMap;
    }

    public Map<Integer, DangerType> getDangerTypeMap() {
        Map<Integer,DangerType> dangerTypeMap = new HashMap<>(10);
        List<DangerType> dangerTypeList = dangerTypeMapper.selectList(new QueryWrapper<>());
        for (DangerType dangerType : dangerTypeList){
            dangerTypeMap.put(dangerType.getId(), dangerType);
        }
        return dangerTypeMap;
    }

    public Map<Integer, DangerLevel> getDangerLevelMap() {
        Map<Integer,DangerLevel> dangerLevelMap = new HashMap<>(10);
        List<DangerLevel> dangerTypeList = dangerLevelMapper.selectList(new QueryWrapper<>());
        for (DangerLevel dangerLevel : dangerTypeList){
            dangerLevelMap.put(dangerLevel.getId(), dangerLevel);
        }
        return dangerLevelMap;
    }
}
